package com.karrysong.blog_springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.karrysong.blog_springboot.service.TagService;
import com.karrysong.blog_springboot.vo.Result;
import com.karrysong.blog_springboot.vo.TagVo;
import com.karrysong.blog_springboot.vo.params.CategoryPage;
import com.karrysong.blog_springboot.vo.params.CategoryParam;
import com.karrysong.blog_springboot.vo.params.TagPage;
import com.karrysong.blog_springboot.vo.params.TagParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: TagController
 * @Author: KarrySong
 * @Date: 2022/8/4 9:34
 * @Description:
 */
@RestController
@RequestMapping("/tags")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping("/hot")
    public Result listHotTags() {
        int limit = 6;
        List<TagVo> tagVoList = tagService.hot(limit);
        return Result.success(tagVoList);
    }

    @GetMapping
    public Result listTags(){
        return tagService.findAll();
    }

    @GetMapping("/detail/{id}")
    public Result findDetailById(@PathVariable("id") Long id){
        return tagService.findDetailById(id);
    }

    @PostMapping("/admin/all")
    public Result getTags(@RequestBody TagPage tagPage){
        return tagService.getTags(tagPage);
    }

    @PostMapping("/admin/change")
    public Result updateCategory(@RequestBody TagParam tagParam){
        return tagService.updateTag(tagParam);
    }

    @PostMapping("/admin/add")
    public Result addCategory(@RequestBody TagParam tagParam){
        return tagService.addTag(tagParam);
    }

    @PostMapping("/admin/delete/{id}")
    public Result deleteTag(@PathVariable Long id){
        return tagService.deleteTag(id);
    }

//    @PostMapping("/deleteList")
//    public Result deleteTagList(@RequestParam(name = "arr") Long[] arr){
//        return tagService.deleteTagList(arr);
//    }

    @GetMapping("/admin/deleteList")
    public Result deleteTagList(Long[] arr){
        return tagService.deleteTagList(arr);
    }


}
